#!/usr/bin/env bash
# Copyright 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Script for copying of ChromeDriver from chrome-unsigned bucket to to the local
# workspace.

set -eu

source "$(dirname "$0")/common.sh"
ensure_linux $0
ensure_release_root

version=$(cat ".version")
src=chrome-unsigned
tgt=unzipped

rm -rf $src
rm -rf $tgt
rm -rf $tgt/chromedriver_linux64
rm -rf $tgt/chromedriver_mac64
rm -rf $tgt/chromedriver_mac64_m1
rm -rf $tgt/chromedriver_win32

mkdir $src
mkdir $tgt
mkdir $tgt/chromedriver_mac64_m1

gsutil cp gs://chrome-unsigned/desktop-5c0tCh/$version/linux64/chromedriver_linux64.zip $src
gsutil cp gs://chrome-unsigned/desktop-5c0tCh/$version/mac64/chromedriver_mac64.zip $src
gsutil cp gs://chrome-unsigned/desktop-5c0tCh/$version/mac-arm64/chromedriver_mac64.zip $src/chromedriver_mac64_m1.zip
gsutil cp gs://chrome-unsigned/desktop-5c0tCh/$version/win-clang/chromedriver_win32.zip $src

unzip $src/chromedriver_linux64.zip -d $tgt
unzip $src/chromedriver_mac64.zip -d $tgt
unzip $src/chromedriver_mac64_m1.zip -d $tgt/chromedriver_mac64_m1/
unzip $src/chromedriver_win32.zip -d $tgt

# TODO: Remove this line after verifying strip has no effect
strip -p $tgt/chromedriver_linux64/chromedriver

echo "$version" > $tgt/.pulled
